package day07;

import java.util.Random;

//需求：生成 n个位数的验证码，（包含，大小写字母和数字）
public class practice1 {
    public static void main(String[] args) {
   /*     String  code =generateVeriCode(5);
    }

    public static String generateVeriCode(int lenth){
        String code ="";
        char[] chs = {'a','b','c','d','e','f','g','h','i','j','k',
                'l','m','n','o','p','q','r','s','t','u','v',
                'w','x','y','z','A','B','C','D','E','F','G',
                'H','I','J','K','L','M','N','O','P','Q','R',
                'S','T','U','V','W','X','Y','Z','0','1','2',
                '3','4','5','6','7','8','9'};
        Random random=new Random();
        for (int i = 0; i <lenth ; i++) {
            int index =random.nextInt(chs.length);
            code+=chs[index];
        }
        System.out.println("验证码为："+code);
        return code ;*/
        String code = yzm(6);
        System.out.println("验证码："+code);

    }

    public static String yzm(int len) {//遇到不明确的数据，第一想法就是做形参
        String code = "";//字符串即是字符的累加
        char[] chs = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
                'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
                'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
                'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
                'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2',
                '3', '4', '5', '6', '7', '8', '9'};//验证码的数据库
        Random random = new Random();
        for (int i = 0; i < len; i++) {
            int index = random.nextInt(chs.length);
            code+=chs[index];
        }

        return code;
    }
}
